#include "Car.h"
#include <iostream>

void SmartCar::set_CAR_ID(string id)
{
     _id=id;
}

string SmartCar::get_ID()
{
     return  _id;
}

void SmartCar:: saveToFile(const string& filename,int sta)
{
    ofstream file(filename, std::ios::app);  
        if (file.is_open()) {  
            // 写入小车编号  
            file << "编号: " << _id << endl;  
  
            // 写入底盘信息 
            file << "底盘 "<< endl;  
            file << "  编号: " << chassis.id << endl;  
            file << "  型号: " << chassis.model << " mm" << endl;  
            file << "  轴距: " << chassis.wheelbase << " mm" << endl; 
            file << "  轮距: " << chassis.track << " mm" << endl; 
            file << "  最小离地间距: " << chassis.groundClearance << " mm" << endl; 
            file << "  最小转弯半径: " << chassis.minTurningRadius << " m" << endl; 
            file << "  驱动形式: " << chassis.driveForm << endl; 
            file << "  最大行程: " << chassis.maxRange << " m" << endl; 
            file << "  轮胎: " << endl; 
            file << "    型号: " << chassis.type << endl; 
            file << "    尺寸: " << chassis.size << " mm" << endl; 
            file << "      "<< endl;
            // 写入AGX套件
            file << "AGX套件 "<< endl;
            file << "  型号: "<< agxKit.model<<endl; 
            file << "  AI: "<< agxKit.ai<<endl; 
            file << "  CUDA核心: "<< agxKit.cudaCores<<endl; 
            file << "  Tensor CORE: "<< agxKit.tensorCores<<endl; 
            file << "  显存: "<< agxKit.videoMemory<<endl; 
            file << "  存储: "<< agxKit.storage<<endl; 
            file << "      "<< endl;
            //双目摄像头
            file << "双目摄像头 "<< endl;
            file << "  型号: "<< stereoCamera.model<<endl; 
            file << "  摄像头: "<< stereoCamera.cameraType<<endl; 
            file << "  RGB帧分辨率: "<< stereoCamera.rgbResolution<<endl; 
            file << "  RGB帧率: "<< stereoCamera.rgbFrameRate<<endl; 
            file << "  FOV: "<< stereoCamera.fov<<endl; 
            file << "  深度帧率: "<< stereoCamera.depthFrameRate<<endl; 
            file << "      "<< endl;

            //多线激光雷达
            file << "多线激光雷达 "<< endl;
            file << "  型号: "<< lidar.model<<endl; 
            file << "  通道数: "<< lidar.channelCount<<endl; 
            file << "  测试范围: "<< lidar.range<<endl; 
            file << "  功耗: "<< lidar.powerConsumption<<endl; 
            file << "      "<< endl;
            // 9轴陀螺仪
            file << "9轴陀螺仪 "<< endl;
            file << "  型号: "<< gyroscope.model<<endl; 
            file << "  厂家: "<< gyroscope.manufacturer<<endl;
            file << "      "<< endl;
            // 液晶显示屏
            file << "液晶显示屏 "<< endl;
            file << "  型号: "<< display.model<<endl; 
            file << "  尺寸: "<< display.size<<endl; 
            file << "      "<< endl;
            //电池模块
            file << "电池模块 "<< endl;
            file << "  参数: "<< battery.parameters<<endl; 
            file << "  对外供电: "<< battery.outputVoltage<<endl; 
            file << "  充电时长: "<< battery.chargeTime<<endl; 
            file << "      "<< endl;
            //输入标识符
           file << "=="<<sta<< endl;

            // 关闭文件  
            file.close();  
        } else {  
            cerr << "Unable to open file " << filename << endl;  
        }  


}

void SmartCar::SET_Chassis()
{
    chassis.setID("dp12345678");  // 底盘编号
    chassis.setModel("SCOUT MINI");  // 型号
    chassis.setWheelbase(451);  // 轴距
    chassis.setTrack(490);  // 轮距
    chassis.setGroundClearance(115);  // 最小离地间隙
    chassis.setMinTurningRadius(0);  // 最小转弯半径
    chassis.setDriveForm("四轮四驱");  // 驱动形式
    chassis.setMaxRange(10000);  // 最大行程，单位为米，这里需要转换为KM
    chassis.setType("公路轮、麦克纳姆轮");  // 轮胎型号
    chassis.setSize(175);  // 轮胎尺寸
}

// 设置AGX套件信息为默认值
void SmartCar::SET_AGXKit() {
    agxKit.setModel("AGX Xavier");
    agxKit.setAI(32);
    agxKit.setCudaCores(512);
    agxKit.setTensorCores(64);
    agxKit.setVideoMemory(32);
    agxKit.setStorage(32);
}
// 设置双目摄像头信息为默认值
void SmartCar::SET_StereoCamera() {
    stereoCamera.setModel("RealSense D435i");
    stereoCamera.setCameraType("D430");
    stereoCamera.setRgbResolution("1920x1080");
    stereoCamera.setRgbFrameRate(30);
    stereoCamera.setFOV("87.58");
    stereoCamera.setDepthFrameRate(90);
}

// 设置多线激光雷达信息为默认值
void SmartCar::SET_LiDAR() {
    lidar.setModel("RS-Helios-16p");
    lidar.setChannelCount(16);
    lidar.setRange(100);
    lidar.setPowerConsumption(8);
}

// 设置电池模块信息为默认值
void SmartCar::SET_Battery() {
    battery.setParameters("24V/15Ah");
    battery.setOutputVoltage(24);
    battery.setChargeTime("2H");
}
// 设置液晶显示屏信息为默认值
void SmartCar::SET_Display() {
    display.setSize(11.6);
    display.setModel("super");
}
// 设置9轴陀螺仪信息为默认值
void SmartCar::SET_Gyroscope() {
    gyroscope.setModel("CH110");
    gyroscope.setManufacturer("NXP");
}

void printCarFromFile(const string &filePath, int sta)
{
   ifstream file(filePath);  
    bool inRange = false; // 标记是否处于指定区间内  
    string line;
    string sta1,sta2;
    sta1 = "--" + to_string(sta);  
    sta2 = "==" + to_string(sta);  
    if (file.is_open()) {  
        while (getline(file, line)) { // 逐行读取文件  
            if (line == sta1) {  
                inRange = true; // 进入指定区间  
                std::cout << line << std::endl; // 打印"--0"  
            } else if (line == sta2) {  
                std::cout << line << std::endl; // 打印"==0"  
                break; // 退出循环，因为我们已经打印了指定区间的所有内容  
            } else if (inRange) {  
                std::cout << line << std::endl; // 如果在指定区间内，则打印该行  
            }  
        }  
        file.close();  
    } else {  
        std::cerr << "Unable to open file" << std::endl;  
    }  
  
    file.close();       
}

// 设置底盘ID
void SmartCar::Chassis::setID(const string &newId)
{
     id = newId;
}
// 设置底盘
void SmartCar::Chassis::setModel(const string &newModel)
{
    model = newModel;
}
//  设置底盘轴距
void SmartCar::Chassis::setWheelbase(double newWheelbase)
{
    wheelbase = newWheelbase;
}
// 设置底盘轮距
void SmartCar::Chassis::setTrack(double newTrack)
{
    track = newTrack;
}
// 设置底盘最小离地间距
void SmartCar::Chassis::setGroundClearance(double newGroundClearance)
{
    groundClearance = newGroundClearance;
}
//  设置底盘最小转弯半径
void SmartCar::Chassis::setMinTurningRadius(double newMinTurningRadius)
{
    minTurningRadius = newMinTurningRadius;
}
// 设置底盘驱动形式
void SmartCar::Chassis::setDriveForm(const string &newDriveForm)
{
     driveForm = newDriveForm;
}
// 设置底盘最大行程
void SmartCar::Chassis::setMaxRange(double newMaxRange)
{
    maxRange = newMaxRange;
}
// 设置底盘轮胎尺寸
void SmartCar::Chassis::setType(const string &newType)
{
    type = newType;
}
// 设置底盘轮胎尺寸
void SmartCar::Chassis::setSize(double newSize)
{
     size = newSize;
}
// 打印底盘信息
void SmartCar::Chassis::print()
{
     cout << "Chassis Info:" << endl;
            cout << "Chassis ID: " << id << endl;
            cout << "Model: " << model << endl;
            cout << "Wheelbase: " << wheelbase << "mm" << endl;
            cout << "Track: " << track << "mm" << endl;
            cout << "Ground Clearance: " << groundClearance << "mm" << endl;
            cout << "Min Turning Radius: " << minTurningRadius << "m" << endl;
            cout << "Drive Form: " << driveForm << endl;
            cout << "Max Range: " << maxRange << "m" << endl;
            cout << "Tire Type: " << type << endl;
            cout << "Tire Size: " << size << "mm" << endl;
}
// 保存底盘信息到文件
void SmartCar::Chassis::save(ofstream &file)
{
    file << "Chassis Info:" << endl;
    file << "Chassis ID: " << id << endl;
    file << "Model: " << model << endl;
    file << "Wheelbase: " << wheelbase << "mm" << endl;
    file << "Track: " << track << "mm" << endl;
    file << "Ground Clearance: " << groundClearance << "mm" << endl;
    file << "Min Turning Radius: " << minTurningRadius << "m" << endl;
    file << "Drive Form: " << driveForm << endl;
    file << "Max Range: " << maxRange << "m" << endl;
    file << "Tire Type: " << type << endl;
    file << "Tire Size: " << size << "mm" << endl;
}
// AGX套件信息的set方法实现
void SmartCar::AGXKit::setModel(const string& newModel) {
    model = newModel;
}
void SmartCar::AGXKit::setAI(int newAI) {
    ai = newAI;
}
void SmartCar::AGXKit::setCudaCores(int newCudaCores) {
    cudaCores = newCudaCores;
}
void SmartCar::AGXKit::setTensorCores(int newTensorCores) {
    tensorCores = newTensorCores;
}
void SmartCar::AGXKit::setVideoMemory(int newVideoMemory) {
    videoMemory = newVideoMemory;
}
void SmartCar::AGXKit::setStorage(int newStorage) {
    storage = newStorage;
}

// AGX套件信息的屏幕输出和文件保存实现
void SmartCar::AGXKit::print() {
    cout << "AGX Kit Info:" << endl;
    cout << "Model: " << model << endl;
    cout << "AI Performance: " << ai << " TOPS" << endl;
    cout << "CUDA Cores: " << cudaCores << endl;
    cout << "Tensor Cores: " << tensorCores << endl;
    cout << "Video Memory: " << videoMemory << "G" << endl;
    cout << "Storage: " << storage << "G" << endl;
}
void SmartCar::AGXKit::save(ofstream& file) {
    file << "AGX Kit Info:" << endl;
    file << "Model: " << model << endl;
    file << "AI Performance: " << ai << " TOPS" << endl;
    file << "CUDA Cores: " << cudaCores << endl;
    file << "Tensor Cores: " << tensorCores << endl;
    file << "Video Memory: " << videoMemory << "G" << endl;
    file << "Storage: " << storage << "G" << endl;
}

// 双目摄像头信息的set方法实现
void SmartCar::StereoCamera::setModel(const string& newModel) {
    model = newModel;
}
void SmartCar::StereoCamera::setCameraType(const string& newCameraType) {
    cameraType = newCameraType;
}
void SmartCar::StereoCamera::setRgbResolution(const string& newRgbResolution) {
    rgbResolution = newRgbResolution;
}
void SmartCar::StereoCamera::setRgbFrameRate(int newRgbFrameRate) {
    rgbFrameRate = newRgbFrameRate;
}
void SmartCar::StereoCamera::setFOV(const string& newFOV) {
    fov = newFOV;
}
void SmartCar::StereoCamera::setDepthFrameRate(int newDepthFrameRate) {
    depthFrameRate = newDepthFrameRate;
}

// 双目摄像头信息的屏幕输出和文件保存实现
void SmartCar::StereoCamera::print() {
    cout << "Stereo Camera Info:" << endl;
    cout << "Model: " << model << endl;
    cout << "Camera Type: " << cameraType << endl;
    cout << "RGB Resolution: " << rgbResolution << endl;
    cout << "RGB Frame Rate: " << rgbFrameRate << endl;
    cout << "Field of View: " << fov << endl;
    cout << "Depth Frame Rate: " << depthFrameRate << endl;
}
void SmartCar::StereoCamera::save(ofstream& file) {
    file << "Stereo Camera Info:" << endl;
    file << "Model: " << model << endl;
    file << "Camera Type: " << cameraType << endl;
    file << "RGB Resolution: " << rgbResolution << endl;
    file << "RGB Frame Rate: " << rgbFrameRate << endl;
    file << "Field of View: " << fov << endl;
    file << "Depth Frame Rate: " << depthFrameRate << endl;
}

// 多线激光雷达信息的set方法实现
void SmartCar::LiDAR::setModel(const string& newModel) {
    model = newModel;
}
void SmartCar::LiDAR::setChannelCount(int newChannelCount) {
    channelCount = newChannelCount;
}
void SmartCar::LiDAR::setRange(double newRange) {
    range = newRange;
}
void SmartCar::LiDAR::setPowerConsumption(double newPowerConsumption) {
    powerConsumption = newPowerConsumption;
}

// 多线激光雷达信息的屏幕输出和文件保存实现
void SmartCar::LiDAR::print() {
    cout << "LiDAR Info:" << endl;
    cout << "Model: " << model << endl;
    cout << "Channel Count: " << channelCount << endl;
    cout << "Range: " << range << "m" << endl;
    cout << "Power Consumption: " << powerConsumption << "W" << endl;
}
void SmartCar::LiDAR::save(ofstream& file) {
    file << "LiDAR Info:" <<

endl;
file << "Model: " << model << endl;
file << "Channel Count: " << channelCount << endl;
file << "Range: " << range << "m" << endl;
file << "Power Consumption: " << powerConsumption << "W" << endl;
}

// 9轴陀螺仪信息的set方法实现
void SmartCar::Gyroscope::setModel(const string& newModel) {
model = newModel;
}
void SmartCar::Gyroscope::setManufacturer(const string& newManufacturer) {
manufacturer = newManufacturer;
}

// 9轴陀螺仪信息的屏幕输出和文件保存实现
void SmartCar::Gyroscope::print() {
cout << "Gyroscope Info:" << endl;
cout << "Model: " << model << endl;
cout << "Manufacturer: " << manufacturer << endl;
}
void SmartCar::Gyroscope::save(ofstream& file) {
file << "Gyroscope Info:" << endl;
file << "Model: " << model << endl;
file << "Manufacturer: " << manufacturer << endl;
}

// 液晶显示屏信息的set方法实现
void SmartCar::Display::setSize(double newSize) {
size = newSize;
}
void SmartCar::Display::setModel(const string& newModel) {
model = newModel;
}

// 液晶显示屏信息的屏幕输出和文件保存实现
void SmartCar::Display::print() {
cout << "Display Info:" << endl;
cout << "Size: " << size << " inches" << endl;
cout << "Model: " << model << endl;
}
void SmartCar::Display::save(ofstream& file) {
file << "Display Info:" << endl;
file << "Size: " << size << " inches" << endl;
file << "Model: " << model << endl;
}

// 电池模块信息的set方法实现
void SmartCar::Battery::setParameters(const string& newParameters) {
parameters = newParameters;
}
void SmartCar::Battery::setOutputVoltage(double newOutputVoltage) {
outputVoltage = newOutputVoltage;
}
void SmartCar::Battery::setChargeTime(const string& newChargeTime) {
chargeTime = newChargeTime;
}

// 电池模块信息的屏幕输出和文件保存实现
void SmartCar::Battery::print() {
cout << "Battery Info:" << endl;
cout << "Parameters: " << parameters << endl;
cout << "Output Voltage: " << outputVoltage << "V" << endl;
cout << "Charge Time: " << chargeTime << endl;
}
void SmartCar::Battery::save(ofstream& file) {
file << "Battery Info:" << endl;
file << "Parameters: " << parameters << endl;
file << "Output Voltage: " << outputVoltage << "V" << endl;
file << "Charge Time: " << chargeTime << endl;
}

